package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.model.vo.StatisticVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.StudentService;
import com.example.mybatisplus.model.domain.Student;

import java.util.List;

@RestController
@RequestMapping("/api/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    //统计
    @GetMapping("barChartData")
    @ResponseBody
    public JsonResponse barChartData(){
        List<StatisticVO> list = studentService.barChartData();
        return JsonResponse.success(list);
    }

    @GetMapping("pieChartData")
    @ResponseBody
    public JsonResponse pieChartData(){
        List<StatisticVO> list = studentService.pieChartData();
        return JsonResponse.success(list);
    }

    @GetMapping("degreeStudentData")
    @ResponseBody
    public JsonResponse degreeStudentData(){
        List<StatisticVO> list = studentService.degreeStudentData();
        return JsonResponse.success(list);
    }

    @GetMapping("bksBedData")
    @ResponseBody
    public JsonResponse bksBedData(){
        List<StatisticVO> list = studentService.bksBedData();
        return JsonResponse.success(list);
    }

    @GetMapping("yjsBedData")
    @ResponseBody
    public JsonResponse yjsBedData(){
        List<StatisticVO> list = studentService.yjsBedData();
        return JsonResponse.success(list);
    }


    @GetMapping("otherBedData")
    @ResponseBody
    public JsonResponse otherBedData(){
        List<StatisticVO> list = studentService.otherBedData();
        return JsonResponse.success(list);
    }

    @GetMapping("benPageList")
    public JsonResponse pageList(Student student, PageDTO dto){
        Page<Student> page = studentService.pageList(student,dto);
        return JsonResponse.success(page);
    }

    @GetMapping("yanPageList")
    public JsonResponse yanPageList(Student student, PageDTO dto){
        Page<Student> page = studentService.yanPageList(student,dto);
        return JsonResponse.success(page);
    }

    @GetMapping("findStudent")
    @ResponseBody
    public JsonResponse findStudent(Student student){
        Student a = studentService.getById(student.getIdStudent());
        return JsonResponse.success(a);
    }

    @PostMapping("bedAllocation")
    public JsonResponse updateBedAllocation(@RequestBody Student student){
        boolean b = studentService.updateById(student);
        return JsonResponse.success(b);
    }
}

